home *** CD-ROM | disk | FTP | other *** search
/ The Fatted Calf / The Fatted Calf.iso / Applications / Audio-DSP / NU / Source / FGWindow.m.image < prev    next >
Encoding:
Text File  |  1992-12-19  |  4.0 KB  |  160 lines

  1. #import "FGWindow.h"
  2. #import <appkit/NXImage.h>
  3. #import <appkit/NXBitmapImageRep.h>
  4. #import <dpsclient/wraps.h>
  5. #import <dpsclient/psops.h>
  6. #import "Nutation.h"
  7. #import <math.h>
  8. #define NXSetWindowLevel _NXSetWindowLevel
  9.  
  10. // this window buffers the foreground (i.e. the targetGlyph) image
  11. // of a GlyphView.  This image is kept in an offscreen window
  12. // called "anImage", which is initially painted transparent.
  13. // All drawing is directed at this offscreen window, and all
  14. // compositing comes from it. 
  15.  
  16. @implementation FGWindow: BGWindow
  17. { id anImage ;
  18. }
  19.  
  20. - erase: (NXRect *) aRect ;
  21. { // erase (to transparent white) aRect within my image
  22.   [anImage lockFocus] ;
  23.   PSgsave() ;
  24. //  PScompositerect(aRect->origin.x, aRect->origin.y,
  25. //    aRect->size.width,aRect->size.height,NX_CLEAR) ;
  26.   PSsetgray(1.0) ;
  27.   PSsetalpha(0.0) ;
  28.   NXRectFill(aRect) ;
  29.   PSgrestore() ;
  30.   [anImage unlockFocus] ;
  31.   return self ;
  32. }
  33.  
  34. - erase ;
  35. { // erase my image
  36.   NXRect aRect = frame ;
  37.   aRect.origin.x = aRect.origin.y = 0.0 ;
  38.   return [self erase: &aRect] ;
  39. }
  40.  
  41. - composite: (int) op fromRect: (const NXRect *) aRect toPoint: (const NXPoint *) aPnt ;
  42. { // actually composite from anImage
  43.   NXRect bRect ;
  44.   NXPoint bPnt ;
  45.   bPnt.x = rint(aPnt->x) ;
  46.   bPnt.y = rint(aPnt->y) ;
  47.   bRect.size = aRect->size ;
  48.   bRect.origin.x = rint(aRect->origin.x) ;
  49.   bRect.origin.y = rint(aRect->origin.y) ;
  50.   [anImage composite:op fromRect: &bRect toPoint: &bPnt] ;
  51.   return self ;
  52. }
  53.  
  54. - composite: (int) op toPoint: (const NXPoint *) aPnt ;
  55. { // actually composite from anImage
  56.   NXRect aRect  ;
  57.   aRect.origin.x = aRect.origin.y = 0.0 ;
  58.   [anImage getSize: &aRect.size] ;
  59.   return [self composite: op fromRect: &aRect toPoint: aPnt] ;
  60. }
  61.  
  62. - composite: (int) op  ;
  63. { // actually composite from anImage
  64.   NXPoint zeroPoint = {0.0,0.0} ;
  65.   return [anImage composite:op toPoint: &zeroPoint] ;
  66. }
  67.  
  68. - flushWindow ;
  69. { // composite anImage over ourselves
  70.   NXPoint aPnt = {0.0,0.0} ;
  71.   [contentView lockFocus] ;
  72.   [anImage composite: NX_SOVER toPoint: &aPnt] ;
  73.   [contentView unlockFocus] ;
  74.   return self ;
  75. }
  76.  
  77. - frame: (NXRect *) aFrame ;
  78. { // this is the "designated" initializer method
  79.   // Frist, make the window which will be seen on-screen
  80.   // when a Glyph is dragged off of its GlyphView
  81.   [super frame: aFrame] ;
  82.   // make an offscreen window to buffer the image
  83.   anImage = [[NXImage alloc] initSize: &aFrame->size] ;
  84.   // paint anImage transparent
  85.   [self erase] ;
  86.   return self ;
  87. }
  88.  
  89. - free ;
  90. { [anImage free] ;
  91.   return [super free] ;
  92. }
  93.  
  94. - highLight: (NXRect *) aRect ;
  95. { // "highlight" aRect in my image.  This is a toggle:
  96.   // call it again to "unhighlight" it.
  97.   [anImage lockFocus] ;
  98.   NXHighlightRect(aRect) ;
  99.   [anImage unlockFocus] ;
  100.   return self ;
  101. }
  102.  
  103. - highLight ;
  104. { // "highlight" my image.  This is a toggle:
  105.   // call it again to "unhighlight" it.
  106.   NXRect aRect = frame ;
  107.   aRect.origin.x = aRect.origin.y = 0.0 ;
  108.   return [self highLight: &aRect] ;
  109.   [anImage unlockFocus] ;
  110.   return self ;
  111. }
  112.  
  113. - image ;
  114. { return anImage ;
  115. }
  116.  
  117. - (BOOL) lockFocus ;
  118. { // we actually lock focus on anImage
  119.   return [anImage lockFocus] ;
  120. }
  121.  
  122. - orderFront: sender ;
  123. { // before I come to the front, I paint myself
  124.   // opaque white and composite anImage onto myself
  125.   NXPoint zeroPoint = {0.0,0.0} ;
  126.   [contentView lockFocus] ;
  127.   PSsetgray(1.0) ;
  128.   PSrectfill(0.0,0.0,frame.size.width,frame.size.height) ;
  129.   [anImage composite: NX_SOVER toPoint: &zeroPoint] ;
  130.   [contentView unlockFocus] ;
  131.   PSsetgray(0.0) ;
  132.   return [super orderFront: sender] ;
  133. }
  134.  
  135. - sizeWindow:(NXCoord)width :(NXCoord)height ;
  136. { // for a Window...[anImage sizeWindow: width :height] ;
  137.   NXSize aSize ;
  138.   aSize.width = width ; aSize.height = height ;
  139.   [anImage setSize: &aSize] ;
  140.   return [super sizeWindow: width :height] ;
  141. }
  142.  
  143. - unlockFocus ;
  144. { // we actually lock focus on anImage
  145.   return [anImage unlockFocus] ;
  146. }
  147.  
  148. - helpMe ;
  149. { NXStream *aStream ;
  150.   aStream = NXOpenMemory(NULL,0, NX_READWRITE);
  151.   if(aStream != NULL)
  152.   { [anImage writeTIFF: aStream] ;
  153.     NXSaveToFile(aStream, "/tmp/helpMe.tiff") ;
  154.     NXCloseMemory(aStream,NX_FREEBUFFER);
  155.   }
  156.   else
  157.     [Nu printf: "can't map file\n"] ;
  158. }
  159.  
  160. @end